package cn.niit.letuseatdemo.controller.user;

import cn.niit.letuseatdemo.entity.domain.User;
import cn.niit.letuseatdemo.service.UserRegisterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @Description 用户注册控制器（网页版）
 * @Author Zhang Shiqi
 * @CreateTime 2022/10/26 19:37
 */
@Slf4j

@Controller
public class RegisterController {

    @Autowired
    private UserRegisterService userRegisterService;
    
    /*
    * @Description: 用于用户访问/user/register后在浏览器中显示注册页面
    * @Author: Zhang Shiqi
    * @CreateTime： 2022/10/30 23:46  
     * @return: java.lang.String 
    **/
    @GetMapping("/user/register")
    public String resgister(){
        return "/user/register";
    }

    /*
    * @Description: 接收用户注册信息
    * @Author: Zhang Shiqi
    * @CreateTime： 2022/10/30 23:47 
     * @param: user
     * @param: session 
     * @return: java.lang.String 
    **/
    @PostMapping("/user/register")
    public String resgisterSave(User user, HttpSession session){
        int rows = userRegisterService.insertUser(user);
        if (rows <= 0){
            return "/user/register";
        }
        return "/user/registerSuc";
    }
}
